<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * BLOG MODEL
 *
 * @author  Ali OYGUR <alioygur@gmail.com>
 */
class Blog_model extends MY_Model
{

	public function __construct()
	{
		parent::__construct();
	}

	public function get($id)
	{
		$q = $this->db->get_where('blog', array('id' => $id), 1);

		if (!$q->num_rows())
			return FALSE;

		return $q->row();
	}

	public function gets($options = array(), $limit = 0, $offset = 0)
	{
		$this->db
			->select("SQL_CALC_FOUND_ROWS t1.*", FALSE)
			->from('blog' . ' AS t1')
			->order_by('t1.order', 'desc');

		// WHERE
		// By category_id
		if (isset($options['category_id']) && $options['category_id'] != 'all')
		{
			$this->db
				->join($this->_table[2] . ' AS t2', 't1.id = t2.blog_id', 'left')
				->where('t2.category_id', $options['category_id']);
		}

		// By status
		if (isset($options['status']))
			$this->db->where('t1.status', $options['status']);

		// LIMIT
		if ($limit > 0)
		{
			$this->db->limit($limit, $offset);
		}

		return parent::my_result();
	}
}

/* End of file blog_model.php */
